<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Boost 搜索引擎</title>
    <script src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        html, body {
            height: 100%;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background: #f2f5f8;
            color: #333;
        }

        .container {
            width: 90%;
            max-width: 900px;
            margin: 30px auto;
        }

        .search {
            display: flex;
            justify-content: center;
            align-items: center;
            margin-bottom: 30px;
        }

        .search input {
            flex: 1;
            height: 48px;
            border: 1px solid #ccc;
            padding: 0 15px;
            font-size: 16px;
            border-radius: 8px 0 0 8px;
            outline: none;
            transition: border-color 0.3s ease;
        }

        .search input:focus {
            border-color: #4e6ef2;
        }

        .search button {
            height: 50px;
            width: 140px;
            background-color: #4e6ef2;
            color: #fff;
            font-size: 16px;
            border: none;
            border-radius: 0 8px 8px 0;
            cursor: pointer;
            transition: background-color 0.3s ease;
        }

        .search button:hover {
            background-color: #3953c6;
        }

        .result .item {
            background-color: #fff;
            border-radius: 10px;
            padding: 15px 20px;
            margin-bottom: 20px;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
            transition: transform 0.2s ease, box-shadow 0.2s ease;
        }

        .result .item:hover {
            transform: translateY(-2px);
            box-shadow: 0 6px 18px rgba(0, 0, 0, 0.12);
        }

        .result .item a {
            font-size: 20px;
            font-weight: bold;
            text-decoration: none;
            color: #1a0dab;
            margin-bottom: 5px;
            display: inline-block;
        }

        .result .item a:hover {
            text-decoration: underline;
        }

        .result .item p {
            font-size: 16px;
            color: #444;
            margin: 8px 0;
        }

        .result .item i {
            display: block;
            font-style: normal;
            color: #006621;
            font-size: 14px;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="search">
            <input type="text" value="请输入搜索关键字" id="query-input">
            <button onclick="Search()">搜索一下</button>
        </div>
        <div class="result">
            <!-- 搜索结果在这里动态生成 -->
        </div>
    </div>

    <script>
        function Search(){
            let query = $("#query-input").val().trim();
            if(query === "") return alert("请输入搜索内容！");
            $.ajax({
                type: "GET",
                url: "/s?word=" + encodeURIComponent(query),
                success: function(data){
                    BuildHtml(data);
                },
                error: function(){
                    alert("请求失败，请检查后端服务是否启动");
                }
            });
        }

        function BuildHtml(data){
            let result_label = $(".result");
            result_label.empty();

            for(let elem of data){
                let div = $("<div>").addClass("item");
                $("<a>").text(elem.title).attr("href", elem.url).attr("target", "_blank").appendTo(div);
                $("<p>").text(elem.summary).appendTo(div);
                $("<i>").text(elem.url).appendTo(div);
                div.appendTo(result_label);
            }
        }
    </script>
</body>
</html>
